home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / utils / console / svgatext.3 / svgatext / SVGATextMode-1.3 / XFREE / common_hw / ICS2595.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-29  |  4.4 KB  |  187 lines

  1. /* $XFree86: xc/programs/Xserver/hw/xfree86/common_hw/ICS2595.c,v 3.6 1995/07/01 10:49:00 dawes Exp $ */
  2.  
  3. /* Norbert Distler ndistler@physik.tu-muenchen.de  95/01/11 */
  4.  
  5. #include "ICS2595.h" 
  6. #include "compiler.h"
  7. #define NO_OSLIB_PROTOTYPES
  8. #include "xf86_OSlib.h"
  9.  
  10. #define WRITEDELAY(x) for(i=0; i<(x); i++) GlennsIODelay();
  11. extern int vgaIOBase;
  12. #if NeedFunctionPrototypes
  13. static void wrtICS2595bit(int);
  14. static Bool SetICS2595(unsigned int, unsigned int, unsigned int);
  15. #else
  16. static void wrtICS2595bit();
  17. static Bool SetICS2595();
  18. #endif
  19.  
  20. Bool
  21. ICS2595SetClock(frequency)
  22.   register long frequency;
  23. {  
  24.   int vgaCRIndex = vgaIOBase + 4;
  25.   int vgaCRReg = vgaIOBase + 5; 
  26.   unsigned int i, FeedDiv, BigD, Location=17;
  27.   
  28.           /* programm ICS2595 clocks */
  29.       if (frequency>MAX_ICS2595_FREQ)
  30.         return FALSE;        /* Frequency too high! */
  31.       
  32.       
  33.           /* calculate POST-DIVIDER */
  34.       BigD = 3;
  35.       if (frequency < MIN_ICS2595_FREQ)
  36.         BigD = 2;
  37.       if (frequency < MIN_ICS2595_FREQ / 2)
  38.         BigD = 1;
  39.       if (frequency < MIN_ICS2595_FREQ / 4)
  40.         BigD = 0;
  41.       frequency <<= (~BigD)&3;         /* negation, two last bits significant */    
  42.       
  43.       if (frequency<MIN_ICS2595_FREQ)
  44.         return FALSE;     /* Frequency too low!  */ 
  45.       
  46.       FeedDiv = (unsigned int) ((frequency*46)/QUARZFREQ);
  47.       if (FeedDiv >= 257)
  48.         FeedDiv -= 257;
  49.       if (FeedDiv >= 256)
  50.         FeedDiv = 255 ;
  51.       
  52.       Location = 0x0d;         /* what clock to reprogram */            
  53.       
  54.       SetICS2595( FeedDiv, BigD, Location);
  55.     
  56.       outb(vgaCRIndex,  0x42);       /* set VCLK */
  57.       outb(vgaCRReg,    Location);
  58.       WRITEDELAY(20);
  59.       outb(vgaCRIndex,  0x5c);
  60.       outb(vgaCRReg,    0x20);       /* STROBE   */
  61.       WRITEDELAY(20);
  62.       outb(vgaCRReg,    0x00);
  63.       usleep(80000);                
  64.   
  65.   return TRUE;
  66.   
  67. }    /* end of ICS2595SetClock */
  68.  
  69.  
  70. static Bool 
  71. #if NeedFunctionPrototypes
  72. SetICS2595(unsigned int N, unsigned int D, unsigned int L)
  73. #else
  74. SetICS2595(N, D, L)
  75.   unsigned int N, D, L;
  76. #endif
  77. {
  78.   int vgaCRIndex = vgaIOBase + 4;
  79.   int vgaCRReg = vgaIOBase + 5;
  80.   unsigned int i;
  81.   
  82.   (void)xf86DisableInterrupts(); 
  83.  
  84.   outb(vgaCRIndex, 0x42); /* Start programming sequence for ICS2595-02 */
  85.   outb(vgaCRReg,   0x00);
  86.   outb(vgaCRIndex, 0x5c);
  87.   outb(vgaCRReg,   0x00);
  88.   usleep(50000);
  89.   outb(vgaCRIndex, 0x42);     /* 'rubble bits' */                 
  90.   outb(vgaCRReg,   0x00);
  91.   outb(vgaCRIndex, 0x5c);
  92.   outb(vgaCRReg,   0x20);
  93.   WRITEDELAY(30);
  94.   outb(vgaCRReg,   0x00);
  95.   WRITEDELAY(30);
  96.   outb(vgaCRIndex, 0x42);
  97.   outb(vgaCRReg,   0x01);
  98.   outb(vgaCRIndex, 0x5c);
  99.   outb(vgaCRReg,   0x20);
  100.   WRITEDELAY(30);
  101.   outb(vgaCRReg,   0x00);
  102.   WRITEDELAY(30); 
  103.   
  104.       /* enable programming of ICS2595 */
  105.   
  106.   wrtICS2595bit(0);              /* start bit must be 0         */
  107.   wrtICS2595bit(0);              /* R/W control -> Write    */
  108.   
  109.   for(i=1; i<6; i++)
  110.     {
  111.       wrtICS2595bit(L&1);         /* Location control        */
  112.       L>>=1;
  113.     }
  114.   
  115.   
  116.   for(i=1; i<9; i++)
  117.     {   
  118.       wrtICS2595bit(N&1);     
  119.       N>>=1;
  120.     }
  121.   
  122.   wrtICS2595bit(0);        /* disable EXTFREQ        */
  123.   
  124.   wrtICS2595bit(D&1);         /* set post-divider             */
  125.   D>>=1;
  126.   wrtICS2595bit(D&1); 
  127.   
  128.   wrtICS2595bit(1);        /* STOP1            */
  129.   wrtICS2595bit(1);        /* STOP2            */
  130.  
  131.   outb(vgaCRIndex, 0x42);
  132.   outb(vgaCRReg, 0x00);      /* End State             */
  133.    
  134.   (void)xf86EnableInterrupts();
  135.   usleep(10000); 
  136.   return TRUE;         
  137. }        
  138.  
  139. static void wrtICS2595bit(bool)
  140.   int bool;
  141.   int vgaCRIndex = vgaIOBase + 4;
  142.   int vgaCRReg = vgaIOBase + 5;
  143.   int i,ti=10;
  144.  
  145.   if (bool==1)
  146.     {
  147.       outb(vgaCRIndex, 0x42);
  148.       outb(vgaCRReg,   0x04);
  149.       WRITEDELAY(ti); 
  150.       outb(vgaCRIndex, 0x5c);
  151.       outb(vgaCRReg,   0x20);
  152.       WRITEDELAY(ti); 
  153.       outb(vgaCRReg,   0x00);
  154.       WRITEDELAY(ti); 
  155.       outb(vgaCRIndex, 0x42);
  156.       outb(vgaCRReg,   0x0c);
  157.       WRITEDELAY(ti); 
  158.       outb(vgaCRIndex, 0x5c);
  159.       outb(vgaCRReg,   0x20);
  160.       WRITEDELAY(ti); 
  161.       outb(vgaCRReg,   0x00);
  162.       WRITEDELAY(ti); 
  163.     }
  164.   else
  165.     {
  166.       outb(vgaCRIndex, 0x42);
  167.       outb(vgaCRReg,   0x00);
  168.       WRITEDELAY(ti);
  169.       outb(vgaCRIndex, 0x5c);
  170.       outb(vgaCRReg,   0x20);
  171.       WRITEDELAY(ti);
  172.       outb(vgaCRReg,   0x00);
  173.       WRITEDELAY(ti);
  174.       outb(vgaCRIndex, 0x42);
  175.       outb(vgaCRReg,   0x08);
  176.       WRITEDELAY(ti);
  177.       outb(vgaCRIndex, 0x5c);
  178.       outb(vgaCRReg,   0x20);
  179.       WRITEDELAY(ti);
  180.       outb(vgaCRReg,   0x00);
  181.       WRITEDELAY(ti);
  182.     }
  183. }         
  184.  
  185. /* End of ICS2595.C */
  186.